package com.yanqu.road.server.cmd.activity.commonsupport;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eUnionActivityGroupType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.CommonUnionSupportProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_COMMON_UNION_SUPPORT_LIST,desc = "获取支持列表")
public class GetUnionSupportListCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        CommonUnionSupportProto.GetUnionSupportListReq req = CommonUnionSupportProto.GetUnionSupportListReq.parseFrom(packet.getBytes());
        int activityId = req.getActivityId();
        ActivityInfo openActivityInfo = ActivityMgr.getOpenActivityInfo(activityId);
        if(!ActivityMgr.activityInShowTime(openActivityInfo)){
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }

        eUnionActivityGroupType type = eUnionActivityGroupType.getType(openActivityInfo.getType());
        if(type == null){
            player.sendPacket(Protocol.C_COMMON_UNION_SUPPORT_LIST, req.toBuilder());
        }else {
            player.sendUnionActivityGroupPacket(Protocol.C_COMMON_UNION_GROUP_SUPPORT_LIST, req.toBuilder(), openActivityInfo.getActivityId());
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_COMMON_UNION_SUPPORT_LIST, CommonUnionSupportProto.GetUnionSupportListResp.newBuilder().setRet(ret));
        }
    }
}
